﻿using System;
using System.Web.Mvc;
using EditorialProyectos.Website.Infrastructure;
using Whoever.Framework.Utils;
using Whoever.Framework.CustomException;
using Whoever.Patterns.MVC.Filters;
using Whoever.Patterns.MVC.Models;

using EditorialProyectos.Website.Models;
using EditorialProyectos.Business;
using EditorialProyectos.Business.Entities;

using Whoever.Framework.Enum;
namespace EditorialProyectos.Website.Controllers
{
    public class CommentController : Controller
    {

        [AJAXExceptionHandler]
        public ActionResult Create(Comment entity)
        {
            try
            {
                //entity.User = SessionState.LoggedInUser;
                if (ModelState.IsValid)
                {
                    var id = ManagerFactory.CommentManager.Insert(entity);
                    return Json(new AJAXResponse { Message = Localized.Message("Create", MessageType.Success), MessageType = MessageType.Success, Success = true, MustRedirect = false, ExtraData = new { id = id } });
                }
                throw new BusinessException(Localized.Message("Model", MessageType.Error));
            }
            catch (BusinessException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new Exception(Localized.Message("Exception", MessageType.Error));
            }
        }

        public ActionResult GetPartial(string partialName)
        {
            var model = new CommentViewModel();

            ManagerFactory.CommentManager.FillSelectablesRelations(model);

            return PartialView(partialName, model);
        }
    }
}
